<template>
  
    
    <transition name="slide">
      <div v-show="isMenuOpen" class="side-menu">
        <nav>
          <router-link to="/" @click.native="closeMenu">首页</router-link>
          <!-- <router-link to="/explore" @click.native="closeMenu">全部车型</router-link> -->
          <router-link to="/shop" @click.native="closeMenu">商城</router-link>
        <router-link to="/advisor" @click.native="closeMenu">汽车智问</router-link>
          <router-link to="/services" @click.native="closeMenu">车主服务</router-link>
          <router-link to="/about" @click.native="closeMenu">关于我们</router-link>
          <router-link to="/news" @click.native="closeMenu">最新资讯</router-link>
        </nav>
      </div>
    </transition>
  
  <div class="app">
    <header>
      <div class="header-content">
        <!-- <div class="menu-icon" @click="toggleMenu" style="margin-right: 0;">
          <svg class="move-line" viewBox="0 0 30 24">
            <path d="M3 12h24M3 6h24M3 18h24" stroke="currentColor" stroke-width="2"/>
          </svg>
        </div> -->
        <h1 class="site-title">极溯智擎</h1>
        <nav>
          <!-- <router-link to="/explore">探索车型</router-link> -->
          <router-link to="/">首页</router-link>
          <router-link to="/shop">购车商城</router-link>
          <router-link to="/advisor">汽车智问</router-link>

         <router-link to="/services">车主服务</router-link>
          <router-link to="/about">关于我们</router-link>
          <router-link to="/news">最新资讯</router-link>
        </nav>
        <div style="flex-grow: 1;"></div>
        <div class="user-menu-container">
          <div class="login-icon" @mouseenter="showMenu = true" @mouseleave="showMenu = false" @click="$router.push('/login')">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor">
              <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
              <circle cx="12" cy="7" r="4" />
            </svg>
          </div>
          
          <transition name="fade">
            <div v-show="showMenu" class="dropdown-menu" @mouseenter="showMenu = true" @mouseleave="showMenu = false">
              <router-link to="/user/info" class="menu-item">
                <span>我的信息</span>
              </router-link>
              <div class="menu-item" @click="logout">
                <span>注销</span>
              </div>
            </div>
          </transition>
        </div>
      </div>
    </header>
    
    <main>
      <router-view></router-view>
    </main>
    
    <footer>
      <div class="footer-content">
        <p>© 2023 汽车4S店 版权所有</p>
      </div>
    </footer>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isMenuOpen: false,
      showMenu: false
    }
  },
  methods: {
    toggleMenu() {
      this.isMenuOpen = !this.isMenuOpen
    },
    closeMenu() {
      this.isMenuOpen = false
    },
    logout() {
      // 删除localStorage中的用户信息
      localStorage.removeItem('userInfo');
      // 跳转到登录页面
      this.$router.push('/login');
      alert('注销成功！');
    }
  },
  name: 'App'
}
</script>

<style>
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  background: #0a0a0a;
  color: #ffffff;
  font-family: 'Helvetica Neue', Arial, sans-serif;
}

.header-content .menu-icon {
  cursor: pointer;
  padding: 0 20px 0 0;
  
  .move-line {
    width: 30px;
    height: 24px;
    color: #fff;
    transition: transform 0.3s ease;
  }
    &:hover .move-line {
      transform: scale(1.1);
    }
  }

  .side-menu {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 170px;
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    z-index: 1000;
    padding: 80px 30px 30px;
    
    nav {
      display: grid;
      gap: 1.2rem;
      
      a {
        color: #ffffff;
        text-decoration: none;
        font-size: 1.1rem;
        padding: 12px 20px;
        border-radius: 8px;
        transition: all 0.2s ease;
        
        &:hover {
          background: #464646;
          transform: translateX(10px);
        }
        &.router-link-exact-active {
          color: #0066cc;
          font-weight: 500;
        }
      }
    }
  }

  .slide-enter-active, .slide-leave-active {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .slide-enter, .slide-leave-to {
    transform: translateX(-100%);
  }


header, footer {
  padding: 1.5rem 2rem;
  position: relative;
  background: rgba(20, 20, 20, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 1.5rem 2rem;
  background: rgba(20, 20, 20, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  position: relative;
  gap: 2rem;
}

.user-menu-container {
  position: relative;
}

.login-icon {
  cursor: pointer;
  width: 24px;
  height: 24px;
  color: #aaa;
  transition: color 0.3s;
}

.login-icon:hover {
  color: #fff;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  background: #2a2a2a;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  min-width: 120px;
  z-index: 100;
}

.menu-item {
  padding: 10px 16px;
  color: #ddd;
  display: block;
  text-decoration: none;
  transition: background-color 0.2s;
}

.menu-item:hover {
  background-color: #3a3a3a;
  color: #fff;
}

.fade-enter-active, .fade-leave-active {
  transition: opacity 0.2s;
}

.fade-enter, .fade-leave-to {
  opacity: 0;
}
.site-title {
  color: #ffffff;
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  line-height: 1.5;
  margin: 0;
}

nav {
  display: flex;
  gap: 2rem;
}

nav a {
  color: #aaa;
  text-decoration: none;
  transition: color 0.3s;
  font-weight: 300;
  letter-spacing: 0.05em;
}

nav a:hover {
  color: #fff;
}

.footer-content {
  text-align: center;
  color: #777;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
}
main {
  flex: 1;
}
</style>